package com.ngkj.zmfptback.sys.initData.util;


import com.ngkj.zmfptback.sys.initData.bean.SysDict;
import org.springframework.util.ObjectUtils;

import java.util.*;

/**
 * @author ChenHN
 * @since 2021/10/26 creation
 **/
public class DictUtil {

    public static Map<String, List<SysDict>> getDictsData(List<SysDict> list, String target) throws RuntimeException {
        Map<String, List<SysDict>> map = new HashMap<>();
        if (ObjectUtils.isEmpty(list)) {
            return map;
        }
        if (ObjectUtils.isEmpty(target)) {
            throw new RuntimeException("目标属性不能为空！");
        }
        Iterator<SysDict> dictLists = list.iterator();
        while (dictLists.hasNext()) {
            SysDict next = dictLists.next();

            String dictType = next.getDictType();
            if (map.containsKey(dictType)) {
                List<SysDict> mapList = map.get(dictType);
                mapList.add(next);
                map.put(dictType, mapList);
            } else {
                List<SysDict> mapList = new ArrayList<>();
                mapList.add(next);
                map.put(dictType, mapList);
            }
        }
        return map;
    }
}
